package com.mjx.service;

import com.mjx.dao.UserRepository;
import com.mjx.entity.User;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by meijingxiang on 2017/3/14.
 */
@Service
public class UserService {

    @Autowired
    UserRepository userRepository;

    public User saveUser(User user){
        User u = userRepository.findByClientIp(user.getClientIp());
        if (u == null){
            return userRepository.save(user);
        }
        return u;
    }

    public User findUserById(String id){
        return userRepository.findOne(new ObjectId(id));
    }

}
